package com.gongyinlian.personalprofilewebsiteserver.config;

import com.gongyinlian.personalprofilewebsiteserver.interceptor.JwtInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web MVC 配置类
 * 配置拦截器、跨域等
 * 
 * @author personal-profile-website
 * @date 2024-10-27
 */
@Configuration
@RequiredArgsConstructor
public class WebMvcConfig implements WebMvcConfigurer {
    
    private final JwtInterceptor jwtInterceptor;
    
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor)
                // 拦截所有请求
                .addPathPatterns("/**")
                // 排除不需要认证的路径
                .excludePathPatterns(
                        // 认证相关接口
                        "/auth/login",
                        "/auth/refresh",
                        "/auth/register",
                        
                        // 测试接口（开发阶段开放）
                        "/test/**",
                        
                        // Swagger文档
                        "/doc.html",
                        "/swagger-ui.html",
                        "/swagger-ui/**",
                        "/swagger-resources/**",
                        "/v3/api-docs/**",
                        "/webjars/**",
                        
                        // Druid监控
                        "/druid/**",
                        
                        // 静态资源
                        "/static/**",
                        "/public/**",
                        "/favicon.ico",
                        
                        // 错误页面
                        "/error"
                );
    }
}

